package com.ymatou.iapi.liveseller.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.GetModelDetailResp;
import com.ymatou.iapi.liveseller.parameter.GetUserModelsBean;
import com.ymatou.iapi.liveseller.service.GetUserModelsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
/**
*查询直播模特信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserModels{
	private static GetUserModelsBean getusermodelsBean;
	private static GetUserModelsCall getusermodelsCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询直播模特信息");
	}

	@Before
	public void caseUp() {
		getusermodelsBean=new GetUserModelsBean();
		getusermodelsCall=new GetUserModelsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getusermodelsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserModels_001() {
		Logger.start(true,"查询直播模特信息成功,模特被选中");
		try {
			int userid=1;
			int liveid=10;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list = new ArrayList<Integer>();
			list.add(id);
			LiveRoomCallService.SetLiveModel(liveid, list);
			
			getusermodelsBean.setLiveId(liveid);
			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();			
			Logger.verifyEquals("200", getusermodelsCall.getString("Code"), "验证code");		
			GetModelDetailResp m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id);}).findAny().get();
			Logger.verifyEquals("nick", m.getNickName(), "验证getNickName");
			Logger.verifyEquals("2", m.getWeight(), "验证getWeight");
			Logger.verifyEquals("1", m.getHeight(), "验证getHeight");
			Logger.verifyEquals(true, m.getChoose(), "验证getChoose");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetUserModels_002() {
		Logger.start(true,"不输入userId失败");
		try {
			int userid=1;
			int liveid=10;
//			LiveRoomCallService.DeleteModel(userid);
//			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
//			List<Integer> list = new ArrayList<Integer>();
//			list.add(id);
//			LiveRoomCallService.SetLiveModel(liveid, list);
			
			getusermodelsBean.setLiveId(liveid);
//			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();			
			Logger.verifyEquals("400", getusermodelsCall.getString("Code"), "验证code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetUserModels_003() {
		Logger.start(true,"不输入liveId查出userid下所有model");
		try {
			int userid=1;
			int liveid=10;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			int id2=LiveRoomCallService.CreateModelCall(userid, 3, 4, "nick2");
			List<Integer> list = new ArrayList<Integer>();
			list.add(id);
//			LiveRoomCallService.SetLiveModel(liveid, list);
			
//			getusermodelsBean.setLiveId(liveid);
			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();	
			Logger.verifyEquals("200", getusermodelsCall.getString("Code"), "验证code");		
			GetModelDetailResp m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id2);}).findAny().get();
			Logger.verifyEquals("nick2", m.getNickName(), "验证getNickName");
			Logger.verifyEquals("4", m.getWeight(), "验证getWeight");
			Logger.verifyEquals("3", m.getHeight(), "验证getHeight");
//			Logger.verifyEquals(true, m.getChoose(), "验证getChoose");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetUserModels_004() {
		Logger.start(true,"输入liveId和userid不匹配失败");
		try {
			int userid=1;
			int liveid=10;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list = new ArrayList<Integer>();
			list.add(id);
			LiveRoomCallService.SetLiveModel(liveid, list);
			
			getusermodelsBean.setLiveId(liveid+1);
			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();			
			Logger.verifyEquals("200", getusermodelsCall.getString("Code"), "验证code");		
			GetModelDetailResp m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id);}).findAny().get();
			Logger.verifyEquals("nick", m.getNickName(), "验证getNickName");
			Logger.verifyEquals("2", m.getWeight(), "验证getWeight");
			Logger.verifyEquals("1", m.getHeight(), "验证getHeight");
			Logger.verifyEquals(false, m.getChoose(), "验证getChoose");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserModels_005() {
		Logger.start(true,"查询直播模特信息成功,模特未被选中");
		try {
			int userid=1;
			int liveid=10;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list = new ArrayList<Integer>();
			list.add(id);
//			LiveRoomCallService.SetLiveModel(liveid, list);
			
			getusermodelsBean.setLiveId(liveid);
			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();			
			GetModelDetailResp m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id);}).findAny().get();
			Logger.verifyEquals("nick", m.getNickName(), "验证getNickName");
			Logger.verifyEquals("2", m.getWeight(), "验证getWeight");
			Logger.verifyEquals("1", m.getHeight(), "验证getHeight");
			Logger.verifyEquals(false, m.getChoose(), "验证getChoose");
			
			LiveRoomCallService.SetLiveModel(liveid, list);
			getusermodelsCall.callService();			
			m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id);}).findAny().get();
			Logger.verifyEquals(true, m.getChoose(), "验证getChoose");
			
			list=new ArrayList<Integer>();
			LiveRoomCallService.SetLiveModel(liveid, list);
			getusermodelsCall.callService();	
			m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id);}).findAny().get();
			Logger.verifyEquals(false, m.getChoose(), "验证getChoose");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserModels_006() {
		Logger.start(true,"查询直播模特信息成功,已删除模特不列出");
		try {
			int userid=1;
			int liveid=10;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list = new ArrayList<Integer>();
			list.add(id);
			LiveRoomCallService.SetLiveModel(liveid, list);
			LiveRoomCallService.DeleteModelById(id, userid);
			getusermodelsBean.setLiveId(liveid);
			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();			
			Logger.verifyEquals("200", getusermodelsCall.getString("Code"), "验证code");		
			Logger.verifyEquals(0, getusermodelsCall.getModelDetailsResp().size(), "删除不显示");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserModels_007() {
		Logger.start(true,"查询直播模特信息成功,包含多个模特");
		try {
			int userid=1;
			int liveid=10;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			int id2=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list = new ArrayList<Integer>();
			list.add(id);
			LiveRoomCallService.SetLiveModel(liveid, list);
			
			getusermodelsBean.setLiveId(liveid);
			getusermodelsBean.setUserId(userid);
			getusermodelsCall.setData(getusermodelsBean);
			getusermodelsCall.callService();			
			Logger.verifyEquals("200", getusermodelsCall.getString("Code"), "验证code");		
			GetModelDetailResp m = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id);}).findAny().get();
			Logger.verifyEquals("nick", m.getNickName(), "验证getNickName");
			Logger.verifyEquals("2", m.getWeight(), "验证getWeight");
			Logger.verifyEquals("1", m.getHeight(), "验证getHeight");
			Logger.verifyEquals(true, m.getChoose(), "验证getChoose");
			
			GetModelDetailResp m2 = getusermodelsCall.getModelDetailsResp().stream().filter(x->{return x.getModelId().equals(id2);}).findAny().get();
			Logger.verifyEquals(false, m2.getChoose(), "验证getChoose");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}